<template>
    <div class="profile-card card-box">
        <h5 class="card-title">
            <!-- <el-icon size="20" color="#f06423"><Postcard /></el-icon> -->
             <img src="@/assets/img/pushpin-icon.png" alt="" style="display: block; width: 14px; margin-right: 10px" />
            {{ $t('profile_card.tit') }}
        </h5>
        <div class="card-text">
            <RouterLink to="/console/user/profile" class="user-picture pic" v-if="props.isShowUserPicture">
                <img :src="userinfo?.avatar_url" class="ele" v-if="userinfo?.avatar_url" />
                <el-icon size="30" color="#fff" v-else><User /></el-icon>
            </RouterLink>
            <div class="user-info">
                <div class="fullname">{{ userinfo?.last_name }} {{ userinfo?.first_name }}</div>
                <div class="city">
                    <span>{{ $t('profile_card.label_1') }}</span>
                    <a :href="`mailto:${userinfo?.email}`">{{ userinfo?.email }}</a>
                </div>
                <div class="institution">
                    <span style="font-weight: bold;">{{ $t('profile_card.label_2') }}</span>
                    {{ userinfo?.institution }}
                </div>
                <div class="lastaccess" v-if="props.isShowLastaccess">
                    <span>{{ $t('profile_card.label_3') }}</span>
                    <template v-if="userinfo">{{ formatLoginTime(userinfo.last_login_time) }}</template>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { computed } from 'vue'

import { useUserStore } from '@/stores/user'
import { formatLoginTime } from '@/utils/global'

const props = defineProps<{
    isShowUserPicture?: Boolean
    isShowLastaccess?: Boolean
}>()

const userStore = useUserStore()

const userinfo = computed(() => userStore.userinfoL)
</script>

<style lang="less" scoped>
.card-text {
    display: flex;
    align-items: flex-start;

    .user-picture {
        margin-right: 15px;
        width: 50px;
        height: 50px;
        background-color: #e6e6e6;
        overflow: hidden;

        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;

        .ele {
            max-height: 100%;
            max-width: 100%;
        }
    }

    .user-info {
        .fullname {
            margin-bottom: 8px;
            font-weight: 700;
            font-size: 22px;
            color: #4c4c4c;
        }

        .city,
        .institution,
        .lastaccess {
            font-size: 15px;
            line-height: 1.66;
            color: #4c4c4c;

            a {
                color: #e63946;

                &:hover {
                    color: #242424;
                }
            }
        }
    }
}
</style>
